package cn.tedu.d17_thread;
/*
 能实现同步效果么---可以
 */
public class D17_Work {
    public static void main(String[] args) {

        D17_Work d=new D17_Work();

        Thread t1=new Thread(){
            public void run(){
                d.test1();
            }
        };
        Thread t2=new Thread(){
            public void run(){
                d.test2();
            }
        };

        t1.start();
        t2.start();

    }

    public synchronized static void test1(){
        Thread t=Thread.currentThread();
        String name=t.getName();
        System.out.println(name+"运行test1()方法");

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name+"运行test1()方法结束");
    }

    public synchronized void test2(){
        Thread t=Thread.currentThread();
        String name=t.getName();
        System.out.println(name+"运行test2()方法");

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name+"运行test2()方法结束");
    }
}
